﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace XthTicketDesktop
{
    /// <summary>
    /// ShowDetailPage.xaml 的交互逻辑
    /// </summary>
    public partial class ShowDetailPage : Page
    {

        public ShowDetailPage()
        {
            InitializeComponent();

            // 使用_apiService来调用API并更新UI
            loadData();
        }

        public async void loadData() {
            string url = "http://api.map.baidu.com/telematics/v3/weather?location=嘉兴&output=json&ak=5slgyqGDENN7Sy7pw29IUvrZ";
            string response = await ApiService.GetAsync(url);

            if (response != null)
            {
                Console.Write(response);
                // 在这里处理响应，例如更新UI
                MessageBox.Show($"响应: {response}");
            }
            else
            {
                MessageBox.Show("请求失败");
            }

            /*
             string url = "https://api.example.com/submit";
            var json = new StringContent("{\"key\":\"value\"}", System.Text.Encoding.UTF8, "application/json");
            string response = await HttpClientHelper.PostAsync(url, json);
    
            if (response != null)
            {
                // 在这里处理响应，例如更新UI
                MessageBox.Show($"响应: {response}");
            }
            */
        }

        private void BackButton_Click(object sender, RoutedEventArgs e)
        {
            if (NavigationService.CanGoBack)
            {
                NavigationService.GoBack();
                //NavigationService.Navigate(new Uri($"/StartPage.xaml", UriKind.Relative));
            }
        }

        private void PurchaseButton_Click(object sender, RoutedEventArgs e)
        {
            // 打开场次弹窗
            SessionPopup SessionPopup = new SessionPopup();
            SessionPopup.Owner = App.Current.MainWindow;
            SessionPopup.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            bool? result = SessionPopup.ShowDialog();
            if (result == true)
            {

                // 处理选择的场次
            }
            NavigationService.Navigate(new Uri($"/LocationSelectPage.xaml", UriKind.Relative));
        }

        //购票须知
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri($"/UserKnowPage.xaml", UriKind.Relative));
        }

        //节目介绍
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri($"/ShowProfilePage.xaml", UriKind.Relative));

        }
    }
}
